<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../../css/swiper.css">
    <title>Document</title>
    <style>
        .swiper-container{
            width: 200px;
            height: 300px;
            border: 1px solid #000;
        }
    </style>
    <script src="../../js/vue.js"></script>
    <script src="../../js//swiper.js"></script>
</head>

<body>
    <div id="app">
        <div v-test="imgs"></div>

    </div>
    <script>
        Vue.directive("test", {update(el, binding, vnode) {
                // console.log(binding.value) //就是数组里面的数据 图片
                var imgs = binding.value
                var nodes = "";
                imgs.forEach(item => {
                    nodes += `<div class="swiper-slide"><img style="width:200px;height:auto" src="${item}"></div>`
                });
                var tmpHtml = `
                <div class="swiper-container">
                    <div class="swiper-wrapper">
                        ${nodes}
                    </div>
                </div>
                `;
                el.innerHTML = tmpHtml;


                var mySwiper = new Swiper('.swiper-container', {
                    autoplay: 1000, //可选选项，自动滑动
                })
            }
        })

        new Vue({
            el: "#app",
            data: {
                imgs: []
            },
            mounted() {
                setTimeout(() => {
                    this.imgs = ['./img/1.jpg', './img/2.jpg', './img/3.jpg']
                }, 1000)

            }
        })
    </script>
</body>

</html>